﻿/*
(c) 2010 - Open Source Business Foundation e. V. (www.osbf.de)
This software is provided under Microsoft Reciprocal License (Ms-RL)
(http://www.microsoft.com/opensource/licenses.mspx#Ms-RL)
All other rights reserved
*/



using System.Data.Services.Providers;
using DataServiceProvider;
using MicroFormatProcessing;

namespace MicroFormatWebRole.OData {
    /// <summary>
    /// This class is the container for OData queried User
    /// </summary>

    public class MfUserDSPResourceList : MfDSPResourceList {
        public MfUserDSPResourceList(DSPContext context, DSPMetadata metadata) : base(context, metadata){
        }


        protected override void LoadData() {
            string[] userPropertyList = { Constants.ODATA_FIELD_USERID, Constants.ODATA_FEED_USERID, Constants.ODATA_FIELD_ROWKEY, Constants.ODATA_COLLECTIONS_MICROFORMATS, Constants.ODATA_COLLECTIONS_TAGS };
            ResourceSet userSet;
            metadata.TryResolveResourceSet(Constants.ODATA_ENTITY_USER, out  userSet);
            UserRepository userRespository = new UserRepository();
            foreach (User user in userRespository.SelectAll()) {

                MfMicroformatDSPResourceList mfList = new MfMicroformatDSPResourceList(context, metadata, user.GetUserId());
                MfTagDSPResourceList tagList = new MfTagDSPResourceList(context, metadata, user.GetUserId());
                DSPResource userResource = CreateResourceObject(userSet.ResourceType, userPropertyList, user.GetUserId(), user.GetUserId(), user.RowKey, mfList, tagList);
                mfList.User = userResource;
                tagList.User = userResource;
                Add(userResource);
            }
        }

    }
}